package com.lvyh.lightframe.multidatasource.datasource;

import com.lvyh.lightframe.multidatasource.common.MultiDataSourceHolder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;

/**
 * @author lvyh 2021/03/20.
 */
public class DynamicRoutingDataSource extends AbstractRoutingDataSource {

    private static Logger logger = LoggerFactory.getLogger(DynamicRoutingDataSource.class);

    @Override
    protected Object determineCurrentLookupKey() {
        String currDatasourceName = MultiDataSourceHolder.get();
        logger.info("Current data source：{}", currDatasourceName);
        return currDatasourceName;
    }
}
